<template>
  <div class="hello">
    <button @click="addInfo">添加项目</button>
    <h1>{{ msg }}</h1>
    <ul>
      <li v-for="info in infos" :key="info.text">
        <span>{{info.text}}</span>
      </li>
    </ul>
  </div>
</template>

<script>

import eventHub from '@/tools/eventHub'
import { mapActions, mapMutations, mapState, mapGetters } from 'vuex'

export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: '项目列表',
      infos: [{
        text: '项目1'
      }, {
        text: '项目2'
      }]
    }
  },
  computed: {
    ...mapGetters(['revertName']),
    ...mapState({
      shortName: state => state.Weixin.shortName
    })
  },
  methods: {
    ...mapActions(['GET_GRAFFITI_LIST']),
    ...mapMutations(['SET_WX_NAME']),
    addInfo () {
      this.infos.push({
        text: `项目${this.infos.length + 1}`
      })
      eventHub.$emit('onHub')
      this.GET_GRAFFITI_LIST()
    }
  },
  created () {
    eventHub.$on('onHub', () => {
      console.log('obHubed')
    })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
$background: green;

body {
  background-color: $background;
}
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  margin: 0 10px;
}
a {
  color: $background;
}
</style>
